<template>
  <div>
    <div class="top">
      <div>
        <img v-lazy="heighQuality.coverImgUrl" alt="" />
      </div>
      <div class="info">
        <p>精品歌单</p>
        <span class="title">{{ heighQuality.name }}</span
        ><br /><br />
        <span class="writer">{{ heighQuality.copywriter }}</span>
      </div>
    </div>

    <div class="gd">
      <div class="head">
        <div class="module" @click="toggle = !toggle">
          全部歌单<i class="el-icon-arrow-right"></i>
          <div class="all" :class="{ show: toggle }">
            <div @click="getall">全部歌单</div>
            <ul>
              <li
                v-for="(i, index) in all"
                :key="i.name + Math.random()"
                @click.stop="change(index, i.name)"
              >
                {{ i.name }}
              </li>
            </ul>
          </div>
        </div>
        <ul>
          <li
            v-for="(i, index) in tags"
            :class="{ active: index == number }"
            @click="change(index, i.name,'1')"
            :key="i.id"
          >
            {{ i.name }}
          </li>
        </ul>
      </div>
      <div class="list">
        <ul>
          <li v-for="i in list" :key="i.id + Math.random()" @click="togd(i.id)">
            <span class="playCount">
              <i class="el-icon-caret-right"></i>
              {{ getPlayCount(i.playCount) }}</span
            >
            <div>
              <img v-lazy="i.coverImgUrl" alt="" />
            </div>
            <div class="name">
              {{ i.name }}
            </div>
          </li>
        </ul>
      </div>
      <div class="fyq">
        <el-pagination
          background
          layout="prev, pager, next"
          :total="100"
          @current-change="update"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      heighQuality: {},
      list: [],
      tags: [],
      all: [],
      number: "s",
      toggle: false,
    };
  },
  computed: {
    getPlayCount() {
      return function (count) {
        if (count >= 10000) {
          count = parseInt(count / 10000);
          return count + "万";
        } else {
          return count;
        }
      };
    },
  },
  methods: {
    togd(id){
      this.$router.push({name:'songlist',query:{id:id}})
    },
    update(page) {
      this.$request({
        url: "/top/playlist?limit=40&offset=" + 40 * (page - 1),
      }).then((success) => {
        this.list = success.data.playlists;
      });
    },
    change(index, cat,flag) {
      this.number = index;
      this.$request({
        url: "/top/playlist?limit=40&cat=" + cat,
      }).then((success) => {
        this.list = success.data.playlists;
      });
     if(!flag){
        this.toggle=!this.toggle
     }
    },
    getall() {
      this.$request({
        url: "/top/playlist?limit=40",
      }).then((success) => {
        this.list = success.data.playlists;
      });
    },
  },
  mounted() {
    this.$request({
      url: "/top/playlist/highquality?limit=1",
    }).then((success) => {
      this.heighQuality = success.data.playlists[0];
    });
    this.$request({
      url: "/top/playlist?limit=40",
    }).then((success) => {
      this.list = success.data.playlists;
    });
    this.$request({
      url: "/playlist/catlist",
    }).then((success) => {
      this.tags = success.data.sub.slice(0, 10);
      this.all = success.data.sub;
    });
  },
};
</script>

<style scoped>
.top {
  display: flex;
  align-items: center;
  height: 200px;
  border-radius: 10px;
  padding: 0 20px;
  background: linear-gradient(
    to right,
    rgb(207, 133, 35),
    rgba(16, 16, 212, 0.342)
  );
}

.top img {
  width: 150px;
  border-radius: 10px;
}
.info {
  padding: 10px;
}
.info p {
  width: 100px;
  height: 30px;
  margin-bottom: 20px;
  border: 1px solid rgb(255, 184, 4);
  color: rgb(255, 183, 0);
  text-align: center;
  line-height: 30px;
  border-radius: 15px;
}
.writer {
  font-size: 14px;
  color: rgb(218, 209, 209);
}
.title {
  color: white;
  font-size: 20px;
}

.head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 20px 0;
}
.head ul {
  display: flex;
  color: gray;
}
.head ul li {
  width: 80px;
  text-align: center;
  height: 20px;
  line-height: 20px;
  cursor: pointer;
}
.module {
  position: relative;
  width: 110px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  border: 1px solid #aaa999;
  border-radius: 15px;
  cursor: pointer;
}
.all {
  display: none;
  position: absolute;
  top: 40px;
  left: -10px;
  z-index: 98;
  width: 970px;
  height: 500px;
  border-radius: 10px;
  background-color: white;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
.all div:nth-child(1) {
  text-align: left;
  height: 50px;
  line-height: 50px;
  padding: 0 20px;
  border-bottom: 1px solid #ccc;
}
.all ul {
  display: flex;
  flex-wrap: wrap;
}
.all ul li {
  width: 100px;
  height: 40px;
  line-height: 40px;
  text-align: center;
}
.all ul li:hover {
  color: #ec4141;
}
.list ul {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}
.list ul li {
  position: relative;
  width: 200px;
  border-radius: 10px;
  margin-bottom: 20px;
}
.list ul li img {
  width: 200px;
  height: 200px;
  border-radius: 10px;
}
.name {
  margin-top: 10px;
}
.playCount {
  position: absolute;
  right: 10px;
  top: 10px;
  color: white;
  font-size: 14px;
}
.fyq {
  margin-top: 10px;
  text-align: center;
  height: 100px;
}
.active {
  color: #ec4141;
  border-radius: 10px;
  background-color: #fdf5f5;
}
.show {
  display: block;
}
</style>